# -*- coding:utf-8 -*-

# @Time    : 2023/8/21 21:33
# @Author  : zengwenjia
# @Email   : zengwenjia@lingxi.ai
# @File    : causal_graph_show.py
# @Software: LLM_internal

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import networkx as nx
import matplotlib.pyplot as plt
import settings
# 为matplotlib设置中文字体路径
plt.rcParams['font.sans-serif'] = ['SimHei']  # SimHei是黑体
if not settings.ONLINE:
    plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题

G = nx.DiGraph()

cots = [
]

# # 读取causal_graph里的txt数据
# with open("causal_graph/children-graph.txt", "r") as f:
#     lines = f.readlines()
#     for line in lines:
#         cots.append(line.strip())
#
# products = []
# with open("causal_graph/products/众安尊享e生·中高端医疗保险2023版.txt", "r") as f:
#     lines = f.readlines()
#     for line in lines:
#         products.append(line.strip())


product_cots = ["少儿医疗保险->小额门诊医疗险->报销额度是几百元、几千元",
                "孩子身体素质差常看门诊 -> 小额门诊医疗险",
                "小额门诊医疗险->适用于普通门诊",
                "少儿医疗保险->小额住院医疗险->一般报销额度从几百到几万",
                "孩子容易出现小毛病或意外-> 小额住院医疗险",
                "小额住院医疗险->从普通疾病到重症的中早期都能涵盖",
                "少儿医疗保险->百万医疗险->报销额度高达上百万",
                "百万医疗险->保费低，保额高，专门针对重大疾病"
                "提前进行重疾风险规避 -> 百万医疗险"
                ]

target_theory = ["用户目标->用户问题",
    "用户目标->用户情境",
    "用户问题->用户偏好",
]

user_target =[
    "用户问题->生病了，不给家里添负担的需求",
    "用户情境->年龄：35岁",
    "用户情境->负债情况：有房贷->房贷6万/年",
    "用户情境->日常支出情况：生活花销10万/年",
    "用户问题->自己发生严重的疾病，未来家里房贷、生活花销有保证",
    "用户问题->看牙，龋齿、拔牙、牙冠能报销的",
    "用户偏好->性价比高，杠杆率高，花费少点儿钱获得足够的保障",
    "用户偏好->门诊和住院的报销是要0免赔，100%能报销的",
]

# 添加年龄分期节点
# age_stages = ['Infant', 'Young Child', 'Older Child', 'Young Teen', 'Older Teen']
# for stage in age_stages:
#     G.add_node(stage)
edge_labels = {}
# sum_cots = cots + product_cots
# sum_cots.append("少儿医疗保险->医疗保险")

sum_cots = target_theory + user_target


def plot_casual_graph(cots):
    for cot in cots:
        nodes = cot.split("->")
        for i in range(len(nodes) - 1):
            node_name_i = nodes[i].strip()
            node_name_j = nodes[i + 1].strip()

            G.add_node(node_name_i)
            G.add_node(node_name_j)
            G.add_edge(node_name_i, node_name_j)

    # 绘制因果图
    plt.figure(figsize=(24, 16))
    pos = nx.spring_layout(G)
    nx.draw(G, with_labels=True, node_color='lightblue', node_size=2500, font_size=15)
    nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=12, rotate=False)
    plt.title('Causal Graph: Age Stage and Insurance Suggestions')
    plt.show()

